package com.sljy.hzk.room;

import android.arch.persistence.room.Database;
import android.arch.persistence.room.Room;
import android.arch.persistence.room.RoomDatabase;
import android.arch.persistence.room.TypeConverters;

import com.sljy.hzk.HzkApplication;
import com.sljy.hzk.entity.DangerDatabaseEntity;
import com.sljy.hzk.entity.TaskBodyEntity;
import com.sljy.hzk.entity.TaskDatabaseEntity;
import com.sljy.hzk.entity.UserEntity;
import com.sljy.hzk.net.service.UserServive;
import com.sljy.hzk.room.dao.DangerDao;
import com.sljy.hzk.room.dao.TaskBodyDao;
import com.sljy.hzk.room.dao.TaskDao;
import com.sljy.hzk.room.dao.UserDao;

/**
 * Created  on 2018/4/3
 * @author 唐开阔
 * @describe
 */
@Database(entities = {UserEntity.class, TaskDatabaseEntity.class, DangerDatabaseEntity.class, TaskBodyEntity.class}, version = 1, exportSchema = false)
public abstract class AppDataBase extends RoomDatabase {
    private static AppDataBase ourInstance;
    public static synchronized AppDataBase getInstance() {
        if (ourInstance == null) {
            ourInstance = Room.databaseBuilder(HzkApplication.getContext(),
                    AppDataBase.class, "hzk")
                    .addMigrations()
                    .allowMainThreadQueries()
                    .build();
        }
        return ourInstance;
    }
    public abstract UserDao getUserDao();
    public abstract TaskDao getTaskDao();
    public abstract DangerDao getDangerDao();
    public abstract TaskBodyDao getTaskBodyDao();

    /**
     * 清空所有数据
     */
    public void deleteDataBase(){
//        getUserDao().deleteAll(getUserDao().getAll());
    }


}
